<template>
  <div  class="field inline">
    <label>{{field.title}}</label>
    <select class="ui dropdown" :id="s_id" v-model="val">
      <option value=""> 请选择{{field.title}}</option>
      <option :value="item.id"  v-for="item in bindItem"> {{item.title}}</option>
    </select>
  </div>
</template>

<script>
  import tool from 'src/util/tool';
  import util from '_util/index';
  import logic from '_logic';

  export default {
    data() {
      return {
        enum_val: null,
        val: "", //所有值
        itemVal:"", //表单值
        s_id:"",
        bindItem:[]
      }
    },
    methods: {
      setSelect(isclear){
        let _this = this;
        if(isclear){
          $("#"+this.s_id).dropdown("clear");
          return;
        }
        $("#"+this.s_id)
        .dropdown({
          allowAdditions: true,
          onChange(value, text){
            _this.val = value;
          }
        });
      },
      updateVo(){
        this.$emit('setVo', this.field.name, this.val);
      },
      getData(){
        let _this = this;
        let url = tool.getApi(this,'Bindconf', 'get_show_type_model');
        util.http.SR(this, url, {}, null,(rs)=>{
          _this.bindItem = rs;
          _this.$nextTick(() => {
            _this.setSelect();
          });
        });
      }
    },
    watch: {
      timestemp:{
        immediate: true,
        handler(val) {
          this.updateVo();
        }
      },
      val(val, old){
        console.log(val);
        if(val == old){
          return
        }
        this.updateVo()
      }
    },
    computed: {
      placeholder() {
        return `请选择${this.field.title}`
      },
    },
    props: ['field', 'type', 'param', 'editType', 'timestemp'],
    components: {
    },
    created() {
      this.s_id = this.field.name+"_"+Math.ceil( Math.random()*10000 );
      this.val = this.field.fval || "";
      this.getData();
    }
  };
</script>

<style lang="less" scoped>
  .ei {
    &-input{
      input{
        width: auto!important;
        min-width: 300px;
      }
    }
  }
</style>
